package com.doge.calcalbum.core.base.adapters

import androidx.recyclerview.widget.RecyclerView
import com.doge.calcalbum.utils.log

class RecyclerDataAdapterObserver(private val view: RecyclerView) :
    RecyclerView.AdapterDataObserver() {
    override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
        log("onItemRangeRemoved $positionStart $itemCount")
    }

    override fun onChanged() {
        log("onChanged")
    }

    override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) {
        log("onItemRangeChanged $positionStart $itemCount $payload")
        if (positionStart == 0) view.scrollToPosition(0)
    }

    override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
        log("onItemRangeInserted $positionStart $itemCount")
        if (positionStart == 0) view.scrollToPosition(0)
    }

    override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
        log("onItemRangeChanged $positionStart $itemCount")
        if (positionStart == 0) view.scrollToPosition(0)
    }

    override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
        log("onItemRangeMoved $fromPosition $toPosition $itemCount")
        if (fromPosition == 0) view.scrollToPosition(0)
    }
}